﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using EasyLottery.Utils;

namespace EasyLottery.Propertiy
{
    class EasyLotteryProperties
    {
        private const string FileName = @"property\formMainProperties.xml";

        public static FormMainProperties FormMainProperties { get; set; } = new FormMainProperties();

        public static void Save()
        {
            var properties = XmlUtils.Serializer(typeof(FormMainProperties), FormMainProperties);
            var fileName = PathUtils.ComposeAbsolutePath(FileName);
            var fileInfo = new FileInfo(fileName);
            fileInfo.Delete();
            using (var fileStream = new FileStream(fileName, FileMode.OpenOrCreate))
            {
                var bytes = Encoding.Default.GetBytes(properties);
                fileStream.Write(bytes, 0, bytes.Length);
            }
        }
    }
}
